<template>
  <div class="section-wrap" style="height:100%;margin-top: 50px;">
      <!-- 头部 -->
      <div class="headerBox">
        <div class="header">
          <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
          量化考核记录
        </div>
      </div>
      <vue-better-scroll
      class="wrapper"
      ref="scrollqq"
      :scrollbar="scrollbarObj"
      :pullDownRefresh="pullDownRefreshObj"
      :pullUpLoad="pullUpLoadObj"
      :startY='parseInt(startY)'
      :freeScroll="true"
      @pullingUp="onPullingUp"
    > 
      <div class="form-section" style="margin-top: 40px;" >
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>考核单位</label>
          </div>
          <div class="input_div">
            <input type="text"
                   v-model="params.checkDepartName"
                   :disabled="isDisabled"/>
            <input type="hidden" v-model="params.CheckDepartId"/>
            <x-icon type="ios-arrow-right" size="22" class="icon-right" @click="getCompany(0)"></x-icon>
          </div>
        </div>
        <div class="form-item form-item-style1" >
          <div class="label-title">
            <label>被考核单位</label>
          </div>
          <div class="input_div">
            <input type="text"
                   v-model="params.beCheckDepartName"
                   :disabled="isDisabled">
            <input type="hidden" v-model="params.beCheckDepartId"/>
            <x-icon type="ios-arrow-right" size="22" class="icon-right" @click="getCompany(1)"></x-icon>
          </div>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询开始时间</label>
          </div>
          <group>
            <datetime v-model="startDate" format="YYYY-MM-DD" clear-text="清除" @on-clear="clearStartDate"></datetime>
          </group>
        </div>
        <div class="form-item form-item-style1">
          <div class="label-title">
            <label>查询结束时间</label>
          </div>
          <group>
            <datetime v-model="endDate" clear-text="清除" @on-clear="clearEndDate"></datetime>
          </group>
        </div>
        <p class="search-btn" @click="search">查询</p>
        <div class="info_div2">
          <div class="form-item">
            <div><span>考核次数：{{totalCount}}次</span></div>
          </div>
        </div>
        <div class="project_div">
          <ul class="project_list">
            <li v-for='(item,index) in accpentlist' :key="index" >
              <v-touch v-on:swipeleft="onSwipeLeft(index)" tag="div">
              <div class="lf" @click="nextStep(item)">
                <input type="text" v-model="item.beDepartName" readonly style="display:inline-block;font-weight: bold;width:130px;white-space:nowrap;overflow-x:hidden;text-overflow:ellipsis;"/>
                <!-- <h3 style="display:inline-block;font-weight: bold;width:112px;white-space:nowrap;overflow-x:scroll;">{{item.beDepartName}}</h3> -->
                <span class="statues" v-if="item.rocordStatus==0" style="color:red;">【未提交】</span>
                <span class="statues" v-else-if="item.rocordStatus!=3&&item.commitDivision!=item.totalDivision"> 【{{item.commitDivision}}/{{item.totalDivision}}】</span>
                <span class="statues" v-else-if="item.rocordStatus!=3&&item.commitDivision==item.totalDivision"
                      style="color:red;">【{{item.commitDivision}}/{{item.totalDivision}}】</span>
                <span class="statues" style="color:green;" v-else>【已完成】</span>
                <span>{{item.checkScore}}</span><p class="classifyOneName"> {{item.checkNo}}</p>
                <p class="classifyOneName">{{item.classifyOneName==null?' ':item.classifyOneName}}</p>
              </div>
              <div class="rf">
                <p class="project_time" style="padding-top: 10px;">{{item.checkDate.substring(0, 10)}}</p>
              </div>
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
               <div style="height: 105px;width: 100px;position: absolute;top:0;right: 0;cursor: pointer" v-if="openRightIndex==index">
                <p style="width:50px;text-align:center;height: 105px;line-height: 105px;background-color: red;color: #fff;float: left" @click="del(item,index)">删除</p>
                <p style="width:50px;text-align:center;height: 105px;line-height: 105px;background-color: #ccc;color: #fff;float: right" @click="openRightIndex=-1">取消</p>
            </div>
               </v-touch>
            </li>

          </ul>
        </div>
      </div>
    </vue-better-scroll>
    <!--classValue 显示隐藏   data树结构  nodeClicK节点点击返回值  name显示的字段  -->
    <div v-transfer-dom>
      <!-- <popup v-model="classValue" width="100%">
        <select-depart @nodeClick='selectedDepart'></select-depart>
      </popup> -->
      <popup v-model="classValue" width="100%">
        <ztree
          :data="data"
          @nodeClick="nodeClick"
          :name="'departName'"

        ></ztree>
      </popup>
    </div>

    <div class="add_btn" @click="GetAssessmentInfo({rocordStatus:0})"></div>
  </div>

</template>
<script>
  import ztree from "@commonComponents/tree"
  import selectDepart from "@commonComponents/selectDepart/selectDepart";
  import formatDate from "../../utils/formatDate";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    Popup
  } from "vux";
import { debuglog } from 'util';
import { all } from 'q';

  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        openRightIndex:-1,
        /*下拉刷新*/
        resultlist: [],
        scrollbarObj: {fade: true},
        pullDownRefreshObj: false,
        pullUpLoadObj: {
          threshold: 0,
          txt: {
            more: "加载更多",
            noMore: "没有更多数据了"
          }
        },
        startY: 0,
        scrollToX: 0,
        scrollToY: 0,
        scrollToTime: 700,
        url: "/api/services/app/Assessment/GetPageList",
        isDisabled: true, // 是否禁止输入
        totalCount: 0, //量化考试
        accpentlist: [],
        classValue: false,
        data: [
          {
            id: 1,
            departName: "",
            departType: "",
            departSir: "",
            children: [
              {
                id: 1,
                departName: '',
                departType: "",
                departSir: "",
              }
            ]
          }
        ],
        params: {
          id: [],
          planId: "",
          startDate: "",
          endDate: "",
          checkDepartId: "",
          beCheckDepartId: "",
          skipCount: 0,
          maxResultCount: 10
        },
        startDate: '',
        endDate: '',
        selectDepartType: 0
      };
    },
    components: {
      ztree,
      selectDepart,
      Popup,
      VueBetterScroll
    },
    created() {
      //this.search();
      var date=new Date();
      this.startDate=date.getFullYear()+'-01-01';
      var month=date.getMonth()+1;
      if(month<10){
        month='0'+month;
      }
      var day=date.getDate();
      if(day<10){
        day='0'+day;
      }
      this.endDate=date.getFullYear()+'-'+month+'-'+day;
      this.getData();
    },
    mounted(){
        let that = this;       
        this.$bridge.registerHandler("setToken", function(data) {
                         that.$store.state.Authorization =
          "Bearer " + data;
            that.search();
        });

        this.connectWebViewJavascriptBridge(function(bridge) {
            bridge.registerHandler("setToken", function(data) {
                             that.$store.state.Authorization =
          "Bearer " + data;
            that.search();

            });
        });
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
            if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge);
            } else {
                document.addEventListener(
                "WebViewJavascriptBridgeReady",
                function() {
                    callback(WebViewJavascriptBridge);
                },
                false
                );
            }
        },
      search() {
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        this.params.skipCount = 0;
        this.$axiosAjax.GetPageListAssessment(this.params).then(res => {
          this.totalCount = res.data.result.totalCount;
          this.accpentlist = res.data.result.items;
        });
      },
      getData() {
        if (this.startDate) {
          this.params.startDate = this.startDate + " 00:00:00";
        }
        if (this.endDate) {
          this.params.endDate = this.endDate + " 00:00:00";
        }
        this.$axiosAjax.GetPageListAssessment(this.params).then(res => {

          this.totalCount = res.data.result.totalCount;
          // this.accpentlist = res.data.result.items;

          let relist = res.data.result.items;
          this.accpentlist = this.accpentlist.concat(relist);
          let totalAllCount = res.data.result.totalCount;
          let resultCount = this.accpentlist.length;
          if (parseInt(resultCount) < parseInt(totalAllCount)) {
            this.$refs['scrollqq'].forceUpdate(true);
          } else {
            this.$refs['scrollqq'].forceUpdate(false);
          }
        });
      },
      GetAssessmentInfo(item) {
        //根据id获取详情
        if (item.rocordStatus == 0) {
          this.$router.push({
            path: "/addRecord",
            query: {id: item.id, classId: item.classifyTwoId, departid: item.beDepartId}
          });
        } else {
          this.$router.push({
            path: "/recordDetails",
            query: {id: item.id, classId: item.classifyTwoId, departid: item.beDepartId}
            //query: { id: val }
          });
        }
      },
      goBack() {
        this.$bridge.callHandler({
              type: 'closePage',
              data: {}
            });
      },
      getCompany(type) {
       this.examinedUnits();
        this.selectDepartType = type;
      },
      examinedUnits() {
        this.$axiosAjax.examinedUnits({parentId: -1}).then((res) => {
          if (res.data.success == true) {            
             this.classValue = true;
             this.data = res.data.result;
            console.log(this.data);
          }
        }).catch(
          (err) => {

          }
        )

      },
      nodeClick(item) {       
          if (this.selectDepartType == 0) {
            this.params.checkDepartId = item.id;
            this.params.checkDepartName = item.departName;
          } else {
            this.params.beCheckDepartId = item.id;
            this.params.beCheckDepartName = item.departName;
          }
          this.classValue = false;        
      },
      getTableTypeList() {
        this.$axiosAjax
          .getTableTypeList(this.params)
          .then(res => {
            if (res.data.result.isSuccess == true) {
              this.tableType = res.data.result.data;
            }
          })
          .catch(err => {
          });
      },
      selectedDepart(data) {
        debugger
        if (this.selectDepartType == 0) {
          this.params.checkDepartId = data.id;
          this.params.checkDepartName = data.departName;
        } else {
          this.params.beCheckDepartId = data.id;
          this.params.beCheckDepartName = data.departName;
        }
        this.classValue = false;
      },
      clearStartDate() {
        this.startDate = "";
      },
      clearEndDate() {
        this.endDate = "";
      },
      onPullingUp() {

        let limitcount = this.accpentlist.length;
        this.params.skipCount = limitcount;
        // if (this.params.skipCount + this.params.maxResultCount < this.totalCount) {
        //   this.params.skipCount = this.params.skipCount + this.params.maxResultCount;
        this.getData();
        // }
      },
      onPullingDown() {
        this.search();
      },
      onSwipeLeft(index){
        this.openRightIndex=index
      },
       nextStep(item) {
         if (item.rocordStatus == 0) {
          this.$router.push({
            path: "/addRecord",
            query: {id: item.id, classId: item.classifyTwoId, departid: item.beDepartId}
          });
        } else {
          this.$router.push({
            path: "/recordDetails",
            query: {id: item.id, classId: item.classifyTwoId, departid: item.beDepartId}
            //query: { id: val }
          });
        }
      },
      del(item,index){
        if(item.rocordStatus!=0){
          this.$vux.toast.text("已提交无法删除")
          return;
        }
        this.openRightIndex=-1
        var ids=[]
        if(!item.canDelete){
          this.$vux.toast.text("无删除权限")
          return;
        }
        ids.push(item.id)
        this.$axiosAjax.deletePlanbyId({id: ids}).then((res) => {
          if (res.data.success == true) {
            this.$vux.toast.text("删除成功")
            this.search();
          }
        }).catch(
          (err) => {

          }
        )
      }
    }
  };
</script>
<style lang="less" scoped>
  .search-btn {
    width: 200px;
    line-height: 36px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
    font-size:16px;
    letter-spacing: 4px;
  }

  .statues {
    font-size: 12px;
    font-weight: bold;

  }

  .classifyOneName {
    font-size: 12px;
    color: #666;
  }

  .lf {
    float: left;
    height: 100%;
    width: 70%;

    line-height: 25px;
  }

  .rf {
    float: right;
    height: 100%;
    width: 30%;
    line-height: 50px;
  }

  .form-item {
    .input_div {
      .vux-x-icon {
        fill: #999;
        float: right;
        margin-top: 18px;
      }

    }
  }

  .project_div {
    .project_list {
      box-sizing: border-box;
      padding-left: 10px;
      li {
        border-bottom: 1px solid #efeff4;
        height: 90px;
        position: relative;
        padding-top: 10px;
        padding-right: 22px;
        h4 {
          width: calc(100% - 50px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }

        p {
          span {
            font-size: 14px;
            color: #666;
          }

          span:first-child {
            margin-right: 40px;
          }

        }

        .project_status {
          margin-top: 14px;
          strong {
            font-size: 12px;
          }

          strong.project_status1 {
            color: #ff7333;
          }

          strong.project_status2 {
            color: #469b7a;
          }

        }

        .vux-x-icon {
          fill: #999;
          right: 20px;
          top: 50%;
          margin-top: -11px;
          position: absolute;
        }

      }
    }
  }

  .add_btn {
    position: fixed;
    background: url('../../assets/imgs/add_pro_icon.png') no-repeat;
    background-size: 62px;
    height: 62px;
    width: 62px;
    right: 30px;
    bottom: 35px;
    z-index: 1111;
  }
</style>
